package com.app.ui.activity.base;

import android.app.Application;
import android.content.Context;

import com.app.net.res.user.User;
import com.app.utiles.other.APKInfo;
import com.app.utiles.other.DataSave;
import com.wxj.zx.R;

import cn.bmob.v3.Bmob;
import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;

/**
 * Created by Administrator on 2016/9/7.
 */
public class BaseApplication extends Application {
    public static BaseApplication application;
    public static Context context;
    private User user;

    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        context = this;
        APKInfo.getInstance().registerCallbacks(this);
        //
        Bmob.initialize(this, "9122ff73712c8e0d5c7d57e456986b5e");
        Bmob.DEBUG = true;
        //
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);
        JGPushInit();
    }

    public void JGPushInit() {
        CustomPushNotificationBuilder builder = new
                CustomPushNotificationBuilder(this,
                R.layout.customer_notitfication_layout,
                R.id.icon,
                R.id.title,
                R.id.text);
        // 指定定制的 Notification Layout
        builder.statusBarDrawable = R.mipmap.push;
        // 指定最顶层状态栏小图标
        builder.layoutIconDrawable = R.mipmap.push;
        // 指定下拉状态栏时显示的通知图标
        JPushInterface.setPushNotificationBuilder(2, builder);
        /*BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(this);
        builder.statusBarDrawable = R.mipmap.push;
         JPushInterface.setDefaultPushNotificationBuilder(builder);*/
    }

    public User getUser() {
        if (user == null) {
            user = (User) DataSave.objectGet(DataSave.USER);
        }
        return user;
    }

    public void setUser(User user) {
        this.user = user;
        DataSave.objectSave(user, DataSave.USER);
    }
}
